package com.phuongtn2.karaoke.activity;

import java.util.ArrayList;
import java.util.List;
import com.phuongtn2.karaoke.R;
import com.phuongtn2.karaoke.adapter.SettingsRoomAdapter;
import com.phuongtn2.karaoke.database.DatabaseHelper;
import com.phuongtn2.karaoke.database.dto.RoomDto;

import android.os.Bundle;
import android.app.Activity;
import android.content.Intent;
import android.view.Menu;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.ListView;

public class SettingsRoomActivity extends Activity implements OnClickListener {

	public List<RoomDto> dtos = new ArrayList<RoomDto>();
	public DatabaseHelper databaseHelper;
	public RoomDto roomDto;
	public SettingsRoomAdapter settingsRoomAdapter;
	public Button btAddRoom;
	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		setContentView(R.layout.activity_settings_room);
		databaseHelper = new DatabaseHelper(getApplicationContext());
		dtos = databaseHelper.getAllRoom();
		if (dtos.size() > 0) {
			settingsRoomAdapter  = new SettingsRoomAdapter(
					getApplicationContext(), dtos,this);
			ListView listView = (ListView) findViewById(R.id.roomListView);	
			listView.setAdapter(settingsRoomAdapter);
			settingsRoomAdapter.notifyDataSetChanged();
		}
		btAddRoom = (Button) findViewById(R.id.btAddRoom);
		btAddRoom.setOnClickListener(this);
		databaseHelper.close();
	}
	@Override
	public void onClick(View v) {
		// TODO Auto-generated method stub
		if (v != null) {
			switch (v.getId()) {
			case R.id.btAddRoom:
				Intent addRoom = new Intent(getApplicationContext(),
						AddRoomActivity.class);
				addRoom.putExtra("type","add");
				startActivity(addRoom);
				break;
			default:
				break;
			}
		} else {
			return;
		}
	}

	@Override
	public boolean onCreateOptionsMenu(Menu menu) {
		// Inflate the menu; this adds items to the action bar if it is present.
		getMenuInflater().inflate(R.menu.home, menu);
		return true;
	}

	

}
